<?php
apf_require_controller('Oa_Attendance_Abstract');
apf_require_class('Bll_Attendance_SpecialDay');
class Oa_Attendance_WorkDayListController extends Oa_Attendance_AbstractController {
    const PAGEROW = 50;
    public function handle_request() {
        $admin_list = $this->apf->get_config('oa_manage');
        if(!in_array($this->uinfo['code'],$admin_list)){
            $this->apf->get_response()->redirect('/',false,false);
        }
        $bll = new Bll_Attendance_SpecialDay();
        $params = $this->request->get_parameters();
        $data = $bll->get_special_days_list($params,self::PAGEROW);
        $page_num = $params['p'];
        $multipage = $this->build_multiPage_info($data['total'],$page_num);
        foreach($data['data'] as $index => $one){
            $data['data'][$index]['s_date'] = substr($one['s_date'], 0,4).'-'.substr($one['s_date'], 4,2).'-'.substr($one['s_date'], 6,2);
            if ($one['start_time']){
                $l = $one['start_time']<1000?1:2;
                $data['data'][$index]['start_time'] = substr($one['start_time'], 0,$l).':'.substr($one['start_time'], $l,2);
            }else{
                $data['data'][$index]['start_time'] = "";
            }
            if ($one['end_time']){
                $l = $one['end_time']<1000?1:2;
                $data['data'][$index]['end_time'] = substr($one['end_time'], 0,$l).':'.substr($one['end_time'], $l,2);
            }else{
                $data['data'][$index]['end_time'] = "";
            }
            $data['data'][$index]['create_time'] = date('Y-m-d H:i:s',$one['create_time']);
        }
        $this->request->set_attribute('data',$data['data']);
        $this->request->set_attribute('multipage',$multipage);
        return "Oa_Attendance_WorkDayList";
    }
    /**
     * 获取翻页
     * @param unknown_type $totalnum 总的页数
     * @param unknown_type $page_num 当前第几页
     * @param array $url_params
     * @param int $uid 用户ID
     */
    public function build_multiPage_info($totalnum,$page_num = 0,$url_params = array()) {
        apf_require_class('Tools_MultiPage');
        //翻页信息
        $url = "/workday/";
        $total_rows = $totalnum;
        if($page_num <= 0){$page_num = 1;}
        $url_params['p'] = $page_num;

        $multipage = Tools_MultiPage::multiPage($url,$url_params, '', $total_rows, self::PAGEROW, 10);
        return $multipage;
    }
}